package com.example.redisstudy1.subscriber;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class MySubscriber implements MessageListener {
    @Autowired
    private RedisTemplate<String,Object> redisTemplate;

    @Override
    public void onMessage(Message message, byte[] pattern) {
        Object channel = redisTemplate.getKeySerializer().deserialize(message.getChannel());
        Object body = redisTemplate.getValueSerializer().deserialize(message.getBody());
        System.out.println(channel);
        System.out.println(body);
        System.out.println("消息接收成功");
    }
}
